# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=ruby-racc
_gemname=racc
# Keep version in sync with "Bundled gems" (https://stdgems.org) for the
# packaged Ruby version.
pkgver=1.7.3
pkgrel=0
pkgdesc="LALR(1) parser generator for Ruby"
url="https://github.com/ruby/racc"
arch="all"
license="BSD-2-Clause AND Ruby"
depends="ruby"
makedepends="
	ruby-dev
	ruby-rake
	ruby-rake-compiler
	ruby-rdoc
	"
checkdepends="
	ruby-test-unit
	ruby-test-unit-ruby-core
	"
subpackages="$pkgname-doc"
source="https://github.com/ruby/racc/archive/v$pkgver/$_gemname-$pkgver.tar.gz"
builddir="$srcdir/$_gemname-$pkgver"

prepare() {
	default_prepare
	sed -i '/require .bundler/d' Rakefile
}

build() {
	rake compile

	gem build $_gemname.gemspec

	gem install \
		--local \
		--install-dir dist \
		--bindir dist/bin \
		--ignore-dependencies \
		--document ri \
		--verbose \
		$_gemname
}

check() {
	rake test
}

package() {
	local gemdir="$pkgdir/$(ruby -e 'puts Gem.default_dir')"

	cd "$builddir"/dist

	mkdir -p "$gemdir"
	cp -r doc extensions gems specifications "$gemdir"/

	mkdir -p "$pkgdir"/usr/bin
	cp -r bin/* "$pkgdir"/usr/bin/

	# Remove unnecessary files and rubbish...
	find "$gemdir"/extensions/ -name mkmf.log -delete

	cd "$gemdir"/gems/$_gemname-$pkgver
	rm -r doc/ ext/
	rm -f ChangeLog README.* TODO
}

doc() {
	pkgdesc="$pkgdesc (ri docs)"

	amove "$(ruby -e 'puts Gem.default_dir')"/doc
}

sha512sums="
8412c021d3fc7f25ccf3a61d56c11df0d8c0b09852d99cc314c8b4931f9c22939dc43ef599801de9a64a69acbd897fb6f215f56702634f2c8b6d69ae3bdfa2b3  racc-1.7.3.tar.gz
"
